/**
 * CostumAdapter.java [V 1.0.0]
 * classes : com.xiaocq.iwordkiller.CostumAdapter
 * xiaocq Create at 2012-4-12 下午9:09:32
 */
package com.xiaocq.wordsgod;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xiaocq.wordsgod.model.Vocabulary;

/**
 * com.xiaocq.iwordkiller.CostumAdapter
 * @author Mystery
 * Create at 2012-4-12 下午9:09:32
 */
public class CostumAdapter extends BaseAdapter{
	private List<Vocabulary> list;
	private LayoutInflater inflater;
	private String explains;
	public CostumAdapter(Context context, List<Vocabulary> list){
		this.list = list;
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public int getCount() {
		return list.size();
	}

	public Object getItem(int position) {
		return list.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if(convertView == null){
			convertView = inflater.inflate(R.layout.wrongset_item, null);
			holder = new ViewHolder();
			holder.displayVocabulary = (TextView) convertView.findViewById(R.id.wrongset_vocabulary);
			holder.displayExplains = (TextView) convertView.findViewById(R.id.wrongset_explains);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		Vocabulary vocabulary = list.get(position);
		holder.displayVocabulary.setText(vocabulary.getEnglish());
		explains = vocabulary.getChinese()[0];
		explains = explains.replaceAll("\\|", "");
		holder.displayExplains.setText(explains);
		return convertView;
	}

	static class ViewHolder{
		TextView displayVocabulary;
		TextView displayExplains;
	}
}
